package com.app.service.impl;

import com.app.bean.Orders;
import com.app.bean.OrdersExample;
import com.app.dao.OrdersMapper;
import com.app.service.OrdersService;
import com.app.util.StringUtilsEx;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @author 师晓峰
 * @version V1.0
 * @date 2023/9/21 20:06
 * @Description:
 */
@Service
public class OrdersServiceImpl implements OrdersService {

    @Autowired
    private OrdersMapper ordersMapper;


    @Override
    public List<Orders> list(String moviename) {
        OrdersExample ordersExample = new OrdersExample();
        PageHelper.startPage(1,5);
        OrdersExample.Criteria criteria = ordersExample.createCriteria();
        ordersExample.setOrderByClause("createtime desc");
        if (StringUtilsEx.isNotEmpty(moviename)) {
            criteria.andMovienameLike("%"+moviename+"%");
        }
        List<Orders> ordersList = ordersMapper.selectByExample(ordersExample);
        return ordersList;
    }



    @Override
    public Orders getById(String id) {
        return ordersMapper.selectByPrimaryKey(Integer.parseInt(id));
    }

    @Override
    public int add(Orders orders) {
        orders.setCreatetime(new Date());
        return ordersMapper.insert(orders);
    }

    @Override
    public int update(Orders orders) {
        return ordersMapper.updateByPrimaryKey(orders);
    }


    @Override
    public int delete(String id) {
        return ordersMapper.deleteByPrimaryKey(Integer.parseInt(id));
    }


}
